package com.me.modules.sys.controller;

import com.me.modules.common.annotation.SysLog;
import com.me.modules.common.controller.BaseController;
import com.me.modules.common.utils.PageUtils;
import com.me.modules.common.utils.Query;
import com.me.modules.common.utils.Result;
import com.me.modules.sys.entity.ExtendFieldValue;
import com.me.modules.sys.service.ExtendFieldValueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 流程扩展数据表
 *
 * @author jindouyun
 */
@RestController
//@RequestMapping("/sys/valuedictionary")
@RequestMapping("/sys/extendFieldValue")
public class ExtendFieldValueController extends BaseController {

    @Resource
    private ExtendFieldValueService valueDictionaryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("valuedictionary:list")
    @SysLog("查询流程扩展值数据")
    public Result list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ExtendFieldValue> valueDictionaryList = valueDictionaryService.queryList(query);
        int total = valueDictionaryService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(valueDictionaryList, total, query.getLimit(), query.getPage());

        return Result.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("valuedictionary:info")
    public Result info(@PathVariable("id") Long id) {
        ExtendFieldValue valueDictionary = valueDictionaryService.queryObject(id);

        return Result.ok().put("valueDictionary", valueDictionary);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("valuedictionary:save")
    public Result save(@RequestBody ExtendFieldValue valueDictionary) {
        valueDictionaryService.save(valueDictionary);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("valuedictionary:update")
    public Result update(@RequestBody ExtendFieldValue valueDictionary) {
        valueDictionaryService.update(valueDictionary);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("valuedictionary:delete")
    public Result delete(@RequestBody Long[] ids) {
        valueDictionaryService.deleteBatch(ids);

        return Result.ok();
    }

}
